package com.xai.pg.util;

import java.math.BigDecimal;

/**
 * @Author xxx
 * @Date 2018-12-24 17:48:43
 * @Desc TypeConvert
 *
 */
public class Convert {

    public static String up(String name, boolean upStart) {
        if (name == null || name.isEmpty()) {
            return "";
        }
        String[] ns = name.split("_");
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < ns.length; i++) {
            String n = ns[i];
            if (n == null || n.isEmpty()) {
                continue;
            }

            if (!upStart && i == 0) {
                sb.append(n);
            } else {
                sb.append(n.substring(0, 1).toUpperCase()).append(n.substring(1, n.length()));
            }
        }

        return sb.toString();
    }

    public static String convert(String type) {
        if (type == null || type.isEmpty()) {
            return "";

        }

        switch (type) {
            case "bit":
                return Boolean.class.getSimpleName();
            case "int":
                return Integer.class
                        .getSimpleName();

            case "tinyint":
                return Integer.class
                        .getSimpleName();

            case "mediumint":
                return Integer.class
                        .getSimpleName();

            case "bigint":
                return Long.class
                        .getSimpleName();

            case "float":
                return Float.class
                        .getSimpleName();

            case "double":
                return Double.class
                        .getSimpleName();

            case "decimal":
                return BigDecimal.class
                        .getName();
            case "tinyblob":
                return "byte[]";
            case "blob":
                return "byte[]";
            case "mediumblob":
                return "byte[]";
            case "longblob":
                return "byte[]";

            case "varchar":
                return String.class
                        .getSimpleName();
            case "char":
                return String.class
                        .getSimpleName();
            case "text":
                return String.class
                        .getSimpleName();

            case "tinytext":
                return String.class
                        .getSimpleName();

            case "mediumtext":
                return String.class
                        .getSimpleName();

            case "longtext":
                return String.class
                        .getSimpleName();
            case "date":
                return String.class
                        .getName();
            case "datetime":
                return String.class
                        .getSimpleName();
            case "timestamp":
                return String.class
                        .getSimpleName();

        }
        return "";
    }
}
